#include <bits/stdc++.h>

using namespace std;
struct NODE
{
	int ans, a, b, c, x;
	bool operator>(const NODE &n) const { return ans > n.ans; }
};
priority_queue<NODE, vector<NODE>, greater<NODE>> q;
int n, k;
int f(int a, int b, int c, int x)
{
	return a * x * x + b * x + c;
}

int main()
{
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		int a, b, c;
		cin >> a >> b >> c;
		q.push({f(a, b, c, 1), a, b, c, 1});
	}
	while (k--)
	{
		NODE t = q.top();
		q.pop();
		q.push({f(t.a, t.b, t.c, t.x + 1), t.a, t.b, t.c, t.x + 1});
		if (k == 0)
			cout << t.ans;
	}
	return 0;
}